package com.luoying.itew.fragment;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.luoying.itew.R;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/5/24.
 * time 2018-5-10
 * author zm
 */
public abstract  class BaseFragment extends Fragment {
    /**
     * loaing对话框
     */
    protected ProgressDialog loadDialog;

    private View rootview;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootview != null) {
            ViewGroup parent = (ViewGroup) rootview.getParent();
            if (parent != null) {
                parent.removeView(rootview);
            }
            return rootview;
        }
        rootview = View.inflate(getContext(), getLayoutResId(), null);
        ButterKnife.bind(this,rootview);
        init();

        return rootview;
    }

    protected void init() {
        loadDialog = new ProgressDialog(getContext());
        loadDialog.setMessage(getString(R.string.load_ing));
        loadDialog.setCanceledOnTouchOutside(false);
    }

    public void JumpToWithAni(Class activity){
        Intent intent = new Intent(getActivity(),activity);
        startActivity(intent);
        getActivity().finish();
        getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }
    public void JumpTo(Class activity){
        Intent intent = new Intent(getActivity(),activity);
        startActivity(intent);
        getActivity().finish();
    }
    public void ClimbToWithAni(Class activity){
        Intent intent = new Intent(getActivity(),activity);
        startActivity(intent);
        getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }
    public void ClimbTo(Class activity){
        Intent intent = new Intent(getActivity(),activity);
        startActivity(intent);
    }
    protected abstract int getLayoutResId();

}
